package com.jwell.IDcard.reader.api;

/**
 * @author 唐旭
 * @version 1.0.0
 * @FileName:
 * @Company: 成都积微物联电子商务有限公司
 * @Date 2017/12/28
 * @remark:
 */
public class IDCardInfo {
    private String name;
    private String gender;
    private String birthday;
    private String address;
    private String IDNumber;
    private String photoPath;

    public IDCardInfo(String content, String photoPath) {
        String[] split = content.replaceAll("\\s+", "-").split("-");
        this.name = split[0];
        String substring = split[1].substring(0, 1);
        if ("1".equals(substring)) {
            this.gender = "男";
        } else if ("2".equals(substring)) {
            this.gender = "女";
        } else {
            this.gender = "其他";
        }
        this.birthday = split[1].substring(3, 11);
        this.address = split[1].substring(11, split[1].length());
        this.IDNumber = split[2].substring(0, 18);
        this.photoPath = photoPath;
    }

    public IDCardInfo(String content) {
        this(content, "");
    }

    public String getName() {
        return name;
    }

    public IDCardInfo setName(String name) {
        this.name = name;
        return this;
    }

    public String getGender() {
        return gender;
    }

    public IDCardInfo setGender(String gender) {
        this.gender = gender;
        return this;
    }

    public String getBirthday() {
        return birthday;
    }

    public IDCardInfo setBirthday(String birthday) {
        this.birthday = birthday;
        return this;
    }

    public String getAddress() {
        return address;
    }

    public IDCardInfo setAddress(String address) {
        this.address = address;
        return this;
    }

    public String getIDNumber() {
        return IDNumber;
    }

    public IDCardInfo setIDNumber(String IDNumber) {
        this.IDNumber = IDNumber;
        return this;
    }

    public String getPhotoPath() {
        return photoPath;
    }

    public IDCardInfo setPhotoPath(String photoPath) {
        this.photoPath = photoPath;
        return this;
    }

    @Override
    public String toString() {
        return "IDCardInfo{" +
                "name='" + name + '\'' +
                ", gender='" + gender + '\'' +
                ", birthday='" + birthday + '\'' +
                ", address='" + address + '\'' +
                ", IDNumber='" + IDNumber + '\'' +
                ", photoPath='" + photoPath + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        IDCardInfo that = (IDCardInfo) o;

        if (name != null ? !name.equals(that.name) : that.name != null) return false;
        if (gender != null ? !gender.equals(that.gender) : that.gender != null) return false;
        if (birthday != null ? !birthday.equals(that.birthday) : that.birthday != null) return false;
        if (address != null ? !address.equals(that.address) : that.address != null) return false;
        if (IDNumber != null ? !IDNumber.equals(that.IDNumber) : that.IDNumber != null) return false;
        return photoPath != null ? photoPath.equals(that.photoPath) : that.photoPath == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (gender != null ? gender.hashCode() : 0);
        result = 31 * result + (birthday != null ? birthday.hashCode() : 0);
        result = 31 * result + (address != null ? address.hashCode() : 0);
        result = 31 * result + (IDNumber != null ? IDNumber.hashCode() : 0);
        result = 31 * result + (photoPath != null ? photoPath.hashCode() : 0);
        return result;
    }
}
